| Plant | Flowers | Date | lon | lat | ele | Month | Year | julian |
|---|---|---|---|---|---|---|---|---|
| Glossoloma oblongicalyx | 4 | 2015-10-19 | -78.59093 | 0.130838 | 2270 | October | 2015 | 292 |
| Gasteranthus quitensis | 2 | 2016-10-17 | -78.59770 | 0.120070 | 1940 | October | 2016 | 291 |
| Kohleria affinis | 1 | 2016-12-13 | -78.59534 | 0.126746 | 2110 | December | 2016 | 348 |
| Columnea ciliata | 3 | 2014-02-27 | -78.59934 | 0.116682 | 1960 | February | 2014 | 58 |
| Columnea medicinalis | 1 | 2014-04-23 | -78.59372 | 0.128700 | 2130 | April | 2014 | 113 |
| Drymonia teuscheri | 3 | 2016-07-28 | -78.59245 | 0.129393 | 2200 | July | 2016 | 210 |
| Plant | Flowers | Date | lon | lat | ele | Month | Year | julian |
|---|---|---|---|---|---|---|---|---|
| Glossoloma oblongicalyx | 4 | 2015-10-19 | -78.59093 | 0.130838 | 2270 | October | 2015 | 292 |
| Gasteranthus quitensis | 2 | 2016-10-17 | -78.59770 | 0.120070 | 1940 | October | 2016 | 291 |
| Kohleria affinis | 1 | 2016-12-13 | -78.59534 | 0.126746 | 2110 | December | 2016 | 348 |
| Columnea ciliata | 3 | 2014-02-27 | -78.59934 | 0.116682 | 1960 | February | 2014 | 58 |
| Columnea medicinalis | 1 | 2014-04-23 | -78.59372 | 0.128700 | 2130 | April | 2014 | 113 |
| Drymonia teuscheri | 3 | 2016-07-28 | -78.59245 | 0.129393 | 2200 | July | 2016 | 210 |
## sink("model/normal_julian.jags")
## cat("
## model {
##
## for (x in 1:Nobs){
##
## #Effect of environment
## mu[x] <- alpha[Plant[x]] + beta[Plant[x]] * ele[x]
##
## #observation
## Yobs[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
##
## #Residuals
## residuals[x] <- Yobs[x] - mu[x]
##
## #squared error
## sq[x]<-pow(residuals[x],2)
##
## #Assess Model Fit - squared residuals
## Ynew[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
## sq.new[x]<-pow(Ynew[x] - mu[x],2)
##
## }
##
## #Root mean squared residuals
## fit<-sqrt(sum(sq[])/Nobs)
## fitnew<-sqrt(sum(sq.new[])/Nobs)
##
## #Prediction
##
## for(i in 1:Npreds){
##
## #predict value
## mu_new[i]<-alpha[Ypred_plant[i]] + beta[Ypred_plant[i]] * ele_new[i]
## prediction[i] ~ dnorm(mu_new[i],tau[Ypred_plant[i]])T(0,365)
##
## #squared predictive error
## pred_error[i] <- pow(Ypred[i] - prediction[i],2)
## }
##
## #Root Mean Squared Predictive Error
## fitpred<-sqrt(sum(pred_error[])/Npreds)
##
## #Priors
##
## #Species level priors
##
## for (j in 1:Plants){
##
## #Intercept
## alpha[j] ~ dnorm(0,0.0001)
##
## #Effect of elevation
## beta[j] <- 0
##
## #variance
## sigma[j] ~ dunif(0,75)
## tau[j] <- pow(sigma[j], -2)
## }
##
## }
## ",fill=TRUE)
##
## sink()
## Compiling model graph
## Resolving undeclared variables
## Allocating nodes
## Graph information:
## Observed stochastic nodes: 6991
## Unobserved stochastic nodes: 8245
## Total graph size: 52619
##
## Initializing model
Red is the kernel density from the underlying data Black is the modeled phenology
## sink("model/normal_attraction.jags")
## cat("
## model {
##
## for (x in 1:Nobs){
##
## #observation
## mu[x] <- alpha + beta[Plant[x]] * ele[x] + e[Plant[x]]
## Yobs[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
##
## #Residuals
## residuals[x] <- Yobs[x] - mu[x]
##
## #squared error
## sq[x]<-pow(residuals[x],2)
##
## #Assess Model Fit - squared residuals
## Ynew[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
## sq.new[x]<-pow(Ynew[x] - mu[x],2)
##
## }
##
## #Root mean squared error
## fit<-sqrt(sum(sq[])/Nobs)
## fitnew<-sqrt(sum(sq.new[])/Nobs)
##
## #autocorrelation in error
## e[1:Plants] ~ dmnorm(zeros[],tauC[,])
##
## ##covariance among similiar species
## for(i in 1:Plants){
## for(j in 1:Plants){
## C[i,j] = exp(-lambda * D[i,j])
## }
## }
##
## ## Covert variance to precision for each parameter, allow omega to shrink to identity matrix
## vCov = omega*C[,] + (1-omega) * I
## iC=inverse(vCov*gamma)
## tauC=iC
## tauC2=iC
##
## ###########
## #Prediction
## ###########
##
## for(i in 1:Npreds){
##
## #predict value
## mu_new[i] <- alpha + beta[Ypred_plant[i]] * ele_new[i] + e[Ypred_plant[i]]
## prediction[i] ~ dnorm(mu_new[i],tau[Ypred_plant[i]])T(0,365)
##
## #squared predictive error
## pred_error[i] <- pow(Ypred[i] - prediction[i],2)
## }
##
## #Root Mean Squared Predictive Error
## fitpred<-sqrt(sum(pred_error)/Npreds)
##
## # Priors #
## ##########
##
## #Species level priors
##
## for (j in 1:Plants){
##
## beta[j] <- 0
##
## #variance
## sigma[j] ~ dunif(0,75)
## tau[j] <- pow(sigma[j], -2)
## }
##
## #Intercept
## alpha ~ dnorm(0,0.0001)
## gamma ~ dunif(0,20)
##
## #Strength of covariance decay
## lambda = 5
## #Magnitude of the phylogenetic effect
## omega ~ dbeta(1,1)
##
## }
## ",fill=TRUE)
##
## sink()
## Compiling model graph
## Resolving undeclared variables
## Allocating nodes
## Graph information:
## Observed stochastic nodes: 6991
## Unobserved stochastic nodes: 8235
## Total graph size: 53070
##
## Initializing model
## sink("model/normal_repulsion.jags")
## cat("
## model {
##
## for (x in 1:Nobs){
##
## #observation
## mu[x] <- alpha + beta[Plant[x]] * ele[x] + e[Plant[x]]
## Yobs[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
##
## #Residuals
## residuals[x] <- Yobs[x] - mu[x]
##
## #squared error
## sq[x]<-pow(residuals[x],2)
##
## #Assess Model Fit - squared residuals
## Ynew[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
## sq.new[x]<-pow(Ynew[x] - mu[x],2)
##
## }
##
## #sum of squared error
## #Root mean squared error
## fit<-sqrt(sum(sq[])/Nobs)
## fitnew<-sqrt(sum(sq.new[])/Nobs)
##
## #autocorrelation in error
## e[1:Plants] ~ dmnorm(zeros[],tauC[,])
##
## ##covariance among similiar species
## for(i in 1:Plants){
## for(j in 1:Plants){
## C[i,j] = exp(-lambda * D[i,j])
## }
## }
##
## #Autocorrelation `signal`, omega shapes the magnitude of the diagonal, as in pagels lambda
## vCov = omega*C[,] + (1-omega) * I
##
## #For clarity sake the inverse is performed, even though it is undone by converting to precision
## #Inverse matrix correlation for repulsion - see Ives and Helmus 2011
## iC=inverse(vCov*gamma)
##
## ## Covert variance to precision for each parameter
##
## iiC=inverse(iC[,])
## tauC=iiC
## tauC2=iiC
##
## ###########
## #Prediction
## ###########
##
## for(i in 1:Npreds){
##
## #predict value
## mu_new[i] <- alpha + beta[Ypred_plant[i]] * ele_new[i] + e[Ypred_plant[i]]
## prediction[i] ~ dnorm(mu_new[i],tau[Ypred_plant[i]])T(0,365)
##
## #squared predictive error
## pred_error[i] <- pow(Ypred[i] - prediction[i],2)
## }
##
## #Root Mean Squared Predictive Error
## fitpred<-sqrt(sum(pred_error)/Npreds)
##
## # Priors #
## ##########
##
## #Julian Intercept
## alpha ~ dnorm(0,0.0001)
## gamma ~ dunif(0,20)
##
## #Species level priors
##
## for (j in 1:Plants){
##
## #effect of elevation
## beta[j] <- 0
##
## #variance
## sigma[j] ~ dunif(0,75)
## tau[j] <- pow(sigma[j], -2)
## }
##
## #Strength of covariance decay
## lambda = 5
## omega ~ dbeta(1,1)
## }
## ",fill=TRUE)
##
## sink()
## Compiling model graph
## Resolving undeclared variables
## Allocating nodes
## Graph information:
## Observed stochastic nodes: 6991
## Unobserved stochastic nodes: 8235
## Total graph size: 53071
##
## Initializing model
## sink("model/normal_attraction.jags")
## cat("
## model {
##
## for (x in 1:Nobs){
##
## #observation
## mu[x] <- alpha + beta[Plant[x]] * ele[x] + e[Plant[x]]
## Yobs[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
##
## #Residuals
## residuals[x] <- Yobs[x] - mu[x]
##
## #squared error
## sq[x]<-pow(residuals[x],2)
##
## #Assess Model Fit - squared residuals
## Ynew[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
## sq.new[x]<-pow(Ynew[x] - mu[x],2)
##
## }
##
## #Root mean squared error
## fit<-sqrt(sum(sq[])/Nobs)
## fitnew<-sqrt(sum(sq.new[])/Nobs)
##
## #autocorrelation in error
## e[1:Plants] ~ dmnorm(zeros[],tauC[,])
##
## ##covariance among similiar species
## for(i in 1:Plants){
## for(j in 1:Plants){
## C[i,j] = exp(-lambda * D[i,j])
## }
## }
##
## ## Covert variance to precision for each parameter, allow omega to shrink to identity matrix
## vCov = omega*C[,] + (1-omega) * I
## iC=inverse(vCov*gamma)
## tauC=iC
## tauC2=iC
##
## ###########
## #Prediction
## ###########
##
## for(i in 1:Npreds){
##
## #predict value
## mu_new[i] <- alpha + beta[Ypred_plant[i]] * ele_new[i] + e[Ypred_plant[i]]
## prediction[i] ~ dnorm(mu_new[i],tau[Ypred_plant[i]])T(0,365)
##
## #squared predictive error
## pred_error[i] <- pow(Ypred[i] - prediction[i],2)
## }
##
## #Root Mean Squared Predictive Error
## fitpred<-sqrt(sum(pred_error)/Npreds)
##
## # Priors #
## ##########
##
## #Species level priors
##
## for (j in 1:Plants){
##
## beta[j] <- 0
##
## #variance
## sigma[j] ~ dunif(0,75)
## tau[j] <- pow(sigma[j], -2)
## }
##
## #Intercept
## alpha ~ dnorm(0,0.0001)
## gamma ~ dunif(0,20)
##
## #Strength of covariance decay
## lambda = 5
## #Magnitude of the phylogenetic effect
## omega ~ dbeta(1,1)
##
## }
## ",fill=TRUE)
##
## sink()
## Compiling model graph
## Resolving undeclared variables
## Allocating nodes
## Graph information:
## Observed stochastic nodes: 6991
## Unobserved stochastic nodes: 8235
## Total graph size: 53226
##
## Initializing model
## sink("model/normal_repulsion.jags")
## cat("
## model {
##
## for (x in 1:Nobs){
##
## #observation
## mu[x] <- alpha + beta[Plant[x]] * ele[x] + e[Plant[x]]
## Yobs[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
##
## #Residuals
## residuals[x] <- Yobs[x] - mu[x]
##
## #squared error
## sq[x]<-pow(residuals[x],2)
##
## #Assess Model Fit - squared residuals
## Ynew[x] ~ dnorm(mu[x],tau[Plant[x]])T(0,365)
## sq.new[x]<-pow(Ynew[x] - mu[x],2)
##
## }
##
## #sum of squared error
## #Root mean squared error
## fit<-sqrt(sum(sq[])/Nobs)
## fitnew<-sqrt(sum(sq.new[])/Nobs)
##
## #autocorrelation in error
## e[1:Plants] ~ dmnorm(zeros[],tauC[,])
##
## ##covariance among similiar species
## for(i in 1:Plants){
## for(j in 1:Plants){
## C[i,j] = exp(-lambda * D[i,j])
## }
## }
##
## #Autocorrelation `signal`, omega shapes the magnitude of the diagonal, as in pagels lambda
## vCov = omega*C[,] + (1-omega) * I
##
## #For clarity sake the inverse is performed, even though it is undone by converting to precision
## #Inverse matrix correlation for repulsion - see Ives and Helmus 2011
## iC=inverse(vCov*gamma)
##
## ## Covert variance to precision for each parameter
##
## iiC=inverse(iC[,])
## tauC=iiC
## tauC2=iiC
##
## ###########
## #Prediction
## ###########
##
## for(i in 1:Npreds){
##
## #predict value
## mu_new[i] <- alpha + beta[Ypred_plant[i]] * ele_new[i] + e[Ypred_plant[i]]
## prediction[i] ~ dnorm(mu_new[i],tau[Ypred_plant[i]])T(0,365)
##
## #squared predictive error
## pred_error[i] <- pow(Ypred[i] - prediction[i],2)
## }
##
## #Root Mean Squared Predictive Error
## fitpred<-sqrt(sum(pred_error)/Npreds)
##
## # Priors #
## ##########
##
## #Julian Intercept
## alpha ~ dnorm(0,0.0001)
## gamma ~ dunif(0,20)
##
## #Species level priors
##
## for (j in 1:Plants){
##
## #effect of elevation
## beta[j] <- 0
##
## #variance
## sigma[j] ~ dunif(0,75)
## tau[j] <- pow(sigma[j], -2)
## }
##
## #Strength of covariance decay
## lambda = 5
## omega ~ dbeta(1,1)
## }
## ",fill=TRUE)
##
## sink()
## Compiling model graph
## Resolving undeclared variables
## Allocating nodes
## Graph information:
## Observed stochastic nodes: 6991
## Unobserved stochastic nodes: 8235
## Total graph size: 53227
##
## Initializing model
To make the graph interesting, take the difference in the minimum elevation and the max elevation and express the effect in days
## # A tibble: 5 x 2
## Model p
## <chr> <dbl>
## 1 julian 0
## 2 phylogenetic_attraction 0
## 3 phylogenetic_repulsion 0
## 4 trait_attraction 0
## 5 trait_repulsion 0
Zoom in #Prediction